import requests
import json

url = "http://localhost:8000/api/chat/completions"  # 请根据实际情况修改URL
headers = {
    'Content-Type': 'application/json',
}

# 示例数据，应根据Ollama API的具体要求调整
start_chat = {
    "model": "qwen2.5:7b",  # 替换为实际使用的模型名称
    "messages": [
        {"role": "system", "content": "只从提供的内容和工具中获取信息,无法获取信息时请说明"},
    ],
    "stream": False
}
history = []
while True:
    # 获取用户输入
    user_input = input("请输入：")
    if user_input.lower() == "exit":
        break

    start_chat["messages"].append({"role": "user", "content": user_input})
    # 发送请求
    response = requests.post(url, headers=headers, data=json.dumps(start_chat))

    # 处理响应
    if response.status_code == 200:
        # 美观地打印响应
        content = response.json()["message"]["content"]
        start_chat["messages"] = response.json()["history"]
        print(f">>>: {content}")


    else:
        print(f"Request failed with status {response.status_code}, response: {response.text}")
